//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    docTempFiles:[],
    category: '数字电路实验室',
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    TabCur: 1,
    scrollLeft: 0,
    laboratories:[],
    show: true,
    cardCur: 0,

    
    swiperList: [
    //   {
    //   id: 0,
    //   type: 'image',
    //   url: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/labs-pic.png?sign=6e85ceff50fdfb0fbd4e3938222a5ea3&t=1619159073'
    // }, {
    //   id: 1,
    //     type: 'image',
    //     url: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/icon/%E6%96%B0%E5%8A%9F%E8%83%BD%E9%A2%84%E6%B5%8B.png?sign=b4384497d2d44235e5badbb5c43fe676&t=1620628264',
    // }, {
    //   id: 2,
    //   type: 'image',
    //   url: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/icon/%E6%96%B0%E5%8A%9F%E8%83%BD%E6%95%88%E6%9E%9C.png?sign=eb4534d8b279d00af73ecc861c88cf4a&t=1620627958'
    // },
    //  {
    //   id: 3,
    //   type: 'image',
    //   url: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/labs-pic.png?sign=6e85ceff50fdfb0fbd4e3938222a5ea3&t=1619159073'
    // },
    //  {
    //   id: 4,
    //   type: 'image',
    //   url: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/icon/%E6%95%88%E6%9E%9C%E6%8F%90%E5%8D%87.png?sign=bae924944df597f1b49995d297e59df6&t=1620628018'
    // }
  ],
    labs:[
      { name: '数字电路实验室'},
      { name: '软件工程实验室'},
      { name: 'Java实验室'},
      { name: '网络安全实验室'},
      { name: '物理力学实验室'},
      { name: '物理光学实验室'},
      { name: '物理电学实验室'},
      { name: '食品科学实验室'},
      { name: '化学实验室'},
      { name: '生物制药实验室'},
      { name: '生物制药实验室'},
      { name: '生物制药实验室'},
      { name: '生物制药实验室'},
      { name: '生物制药实验室'},
      { name: '生物制药实验室'},
      { name: '生物制药实验室'},
      { name: '生物制药实验室'}
    ],

    suitList:[
      // { title: "《移位寄存器及其应用》实验配套仪器", desc:"了解数字示波器、数字信号源以及数字逻辑箱在中小规模数字电路测试和设计中的用途。初步掌握数字示波器、数字信号源以及数字逻辑箱的基本使用方法。" , imageUrl:'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/realtimeInfo/%E7%9F%B3%E5%A2%A8%E7%83%AF.jpg?sign=4fdd6bf5e24148f0e0bbe6bb91f5fb73&t=1621315303'}
    ]
  },
  onLoad(){
   this.getSwiperList()
   this.getsuitlist()
  },

  getSwiperList(){
    wx.cloud.callFunction({
      name:"getlabSwiper",
      data:{
        category: this.data.category
      }
    }).then(res=>{
      this.setData({
        swiperList: res.result.data
      })
    })
  },
  getsuitlist(){
    wx.cloud.callFunction({
      name:"getsuitlist",
      data:{
        category: this.data.category
      }
    }).then(res=>{
      this.setData({
        suitList: res.result.data
      })
    })
  },
  tolabDetail(e){
    wx.navigateTo({
      url: "/pages/lab-navigation/details?labName="+ e.currentTarget.dataset.name,
    })
  },

  // 动态设置导航栏标题
  changeTitle(){ 
     wx.setNavigationBarTitle({
      title: this.data.category?this.data.category: 'NCU实验室',
    })
  },

  // 切换类别
  changeCategory(e){
    // console.log(e)
    this.setData({
      category: e.currentTarget.dataset.category
    })
    this.changeTitle()
    this.hideModal()
    this.getSwiperList()
    this.getsuitlist()
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  tabSelect(e) {
    console.log(e);
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
  },

  turnToUploadFile(){
    // 获取 userInfo
    let userInfo = wx.getStorageSync('userInfo')
    if(userInfo == ""){
      wx.showToast({
        title: '未登录',
        icon: "error"
      }) 
    }else if( userInfo.role == '学生'){
      wx.showToast({
        title: '无权限',
        icon: "error"
      }) 
    }else{
      wx.chooseMessageFile({
        count: 3,
        type: 'file'
      }).then(res=>{
          console.log(res.tempFiles)  
          this.setData({
            docTempFiles : res.tempFiles
          })
      })

      // console.log(this.data.docTempFiles)
      // wx.navigateTo({
      //   url: "/pages/upload-file/index",
      // })

      // this.data.docTempFiles.forEach(item => {
      //   wx.cloud.uploadFile({
      //     cloudPath: "files/"  + Date.now()+ '-' + item.name,
      //     filePath: item.path
      //   }).then(res=>{
      //     console.log(res)
      //   })
      // });
    }
  },
  toinstrument(){
    wx.navigateTo({
      url: "/pages/instrument/suit",
    })
  },
  moreMenu(){
    // wx.showToast({
    //   title: '噜啦噜！FE加班中！',
    //   icon: 'none'
    // })
    wx.navigateTo({
      url: "/pages/instrument/index",
    })
  }
})
